package com.demo.controller;


import com.demo.annotation.GlobalInterceptor;
import com.demo.annotation.VerifyParam;
import com.demo.entity.po.WebCarousel;
import com.demo.entity.query.WebCarouselQuery;
import com.demo.entity.vo.ResponseVO;
import com.demo.service.WebCarouselService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * app轮播 Controller
 */
@RestController("appCarouselController")
@RequestMapping("/appCarousel")
public class AppCarouselController extends ABaseController {

    @Resource
    private WebCarouselService appCarouselService;

    /**
     * 根据条件分页查询
     */
    @RequestMapping("/loadDataList")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO loadDataList(WebCarouselQuery query) {
        query.setOrderBy("sort asc");
        return getSuccessResponseVO(appCarouselService.findListByParam(query));
    }

    /**
     * 首页加载
     * @return
     */
    @RequestMapping("/loadCarousel")
    @GlobalInterceptor(checkLogin = false)
    public ResponseVO loadCarousel() {
        WebCarouselQuery query = new WebCarouselQuery();
        query.setOrderBy("sort asc");
        List<WebCarousel> carouselList = appCarouselService.findListByParam(query);
        return getSuccessResponseVO(carouselList);
    }


    /**
     * 保存轮播图
     * @param webCarousel
     * @return
     */
    @RequestMapping("/saveCarousel")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO saveCarousel(WebCarousel webCarousel) {
        appCarouselService.saveCarousel(webCarousel);
        return getSuccessResponseVO(null);
    }


    /**
     * 删除轮播图
     * @param carouselId
     * @return
     */
    @RequestMapping("/delCarousel")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO delCarousel(@VerifyParam(required = true) Integer carouselId) {
        appCarouselService.deleteWebCarouselByCarouselId(carouselId);
        return getSuccessResponseVO(null);
    }


    /**
     * 改变排序
     * @param carouselIds
     * @return
     */
    @RequestMapping("/changeSort")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO changeSort(@VerifyParam(required = true) String carouselIds) {
        appCarouselService.changeSort(carouselIds);
        return getSuccessResponseVO(null);
    }
}